clear all
set more off


local out2="\outregsQJE\"
local SSA="\Data_and_Codes\"
cd "\workfiles"

use step001_QJE_2, clear

*** keep only matched firms/dates
*** employment
joinby firm_id time using "`SSA'CGR_2006q1_2019q1_clean_ONLYINPSADD.dta", unmatched(master)
tab _merge

gen lnL_new=log(add_new)*100

tsset firm_id time

*** define treatment as given inflation TIMES treatment status
gen Treat=treatment_old*infl

*** use SSA data for employment if SIGE employment is exactly at 50
gen dlnL=d.lnL
winsor dlnL, gen(dlnL_w2) p(0.02)

*** winsorize actual and expected price changes
winsor dprez, gen(dprez_w) p(0.02)

local controls0=" l2.dprez_w i.l2.sitimp5 i.l2.occtot i.l2.sitgen i.l2.promig i.l2.liquid "	

*** restrict the sample only to the period with treatment and control groups
keep if time>=208


***======================================================
*** 					IRF: cumulative [from levels]
***						No firm FE
***======================================================

***=============================================================================
*** 						Panel A: employment (SIGE) response
***							restrict the sample to MORE THAN 50 (>50) employees
***=============================================================================

forvalues i=0(1)5 {

	gen FC`i'=f`i'.lnL-l.lnL
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	ivreghdfe FC`i'_w2 `controls0' (l.it12_all = l.Treat) ///
			[aw=peso] if add>50, ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'AppendixTable09_PanelA.dta", replace dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
	else {
		outreg2 using "`out2'AppendixTable09_PanelA.dta", append dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
}


***=============================================================================
*** 						Panel A: employment (SIGE) response
***							replace employment growth from INPS
***							if SIGE employment == 50
***=============================================================================

forvalues i=0(1)5 {

	capture drop FC`i'
	gen FC`i'=f`i'.lnL-l.lnL
	capture drop FC`i'_w2
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	capture drop aFC`i'
	gen aFC`i'=f`i'.lnL_new-l.lnL_new
	capture drop aFC`i'_w2
	winsor aFC`i', gen(aFC`i'_w2) p(0.02)
	
	replace FC`i'_w2=aFC`i'_w2 if add==50
	
	ivreghdfe FC`i'_w2 `controls0' (l.it12_all = l.Treat) ///
			[aw=peso], ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'AppendixTable09_PanelB.dta", replace dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
	else {
		outreg2 using "`out2'AppendixTable09_PanelB.dta", append dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
}



